define(function(require, exports, module) {

  require('http://localhost/d/threejs-0.106.2/examples/js/loaders/MTLLoader')
  require('http://localhost/d/threejs-0.106.2/examples/js/loaders/OBJLoader')

  let onProgress = function ( xhr ) {
    if ( xhr.lengthComputable ) {
      let percentComplete = xhr.loaded / xhr.total * 100;
      console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
    }
  };

  let onError = function (error) {
    console.log( 'An error happened', error );
  };

  let objMtls = {}

  return function getLoadObjMtl() {

    return function loadObjMtl(name, mark) {
      return new Promise(resolve => {
        if (objMtls[name]) {
          resolve({ mark: mark, data: objMtls[name] })
          return;
        }
        new THREE.MTLLoader()
          .setPath('/assets/model/')
          .load( `${name}.mtl`, function ( materials ) {

            materials.preload();

            new THREE.OBJLoader()
              .setPath('/assets/model/')
              .setMaterials(materials)
              .load(`${name}.obj`, function (object3D) {
                
                objMtls[name] = object3D;

                resolve({ mark: mark, data: object3D });
              }, onProgress, onError);
          })
      })
    }
  }
})
